/**
 * 权限指令
 * @author 木人心
 * @version 1.0.0
 */
import { Directive } from 'vue'
import Authorization from '@utils/authorization'

/**
 * 权限指令
 * 使用方法：v-permission="[arg1, arg2]"
 * @param arg1 number | string | number[] | string[] 权限ID
 * @param arg2 number[] | string[] 角色ID
 */
const Permission: Directive = {
  mounted (el, binding) {
    const [itemPermission = '', itemRole = []] = binding.value
    const authResult = Authorization.authorizedCheck(itemPermission, itemRole.map(item => item.toString()))
    if (!authResult) el.remove()
  }
}

export default Permission
